package com.unis.datapush.service.impl.paxy;

import com.unis.datapush.mapper.zhlg.ZhHotelDataMapper;
import com.unis.datapush.service.paxy.SafeSchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class SafeSchoolServiceImpl implements SafeSchoolService {

    @Autowired
    private ZhHotelDataMapper zhHotelDataMapper;

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Override
    public List<Map<String, Object>> getViolentCrimeMsg() throws Exception {
        //获取人像信息
        List<Map<String, Object>> resu = new ArrayList<Map<String, Object>>();
        String startTime = (String) redisTemplate.opsForValue().get("crcj");
        List<Map<String, Object>> zprxMsg = zhHotelDataMapper.getZprxMsg(startTime);
        if(zprxMsg != null && zprxMsg.size()>0){
            redisTemplate.opsForValue().set("crcj",zprxMsg.get(0).get("CRSJ"));
            for (Map<String, Object> zp:zprxMsg) {
                String sfzh = String.valueOf(zp.get("KSID_CARD"));
                //通过人像信息身份证号获取重点人员信息
                List<Map<String, Object>> violentCrimeMsg = zhHotelDataMapper.getViolentCrimeMsg(sfzh);
                if(violentCrimeMsg != null && violentCrimeMsg.size()>0){
                    for (Map<String, Object> v:violentCrimeMsg) {
                        String yjMsg = "【严重暴力犯罪前科人员预警】XXX发现有严重暴力犯罪前科人员，请进行关注。";
                        v.put("yjMsg",yjMsg);
                        resu.add(v);
                    }
                }
            }
        }

        return resu;
    }

    @Override
    public List<Map<String, Object>> getExtremeViolenceMsg() throws Exception {
        //获取人像信息
        List<Map<String, Object>> resue = new ArrayList<Map<String, Object>>();
        String startTime = (String) redisTemplate.opsForValue().get("crcj");
        List<Map<String, Object>> zprxeMsg = zhHotelDataMapper.getZprxMsg(startTime);
        if(zprxeMsg != null && zprxeMsg.size()>0){
            redisTemplate.opsForValue().set("crcj",zprxeMsg.get(0).get("CRSJ"));
            for (Map<String, Object> zpv:zprxeMsg) {
                String sfzh = String.valueOf(zpv.get("KSID_CARD"));
                //通过人像信息身份证号获取重点人员信息
                List<Map<String, Object>> ExtremeViolence = zhHotelDataMapper.getExtremeViolenceMsg(sfzh);
                if(ExtremeViolence != null && ExtremeViolence.size()>0){
                    for (Map<String, Object> v:ExtremeViolence) {
                        String yjMsg = "【个人极端暴利重点人口预警】XXX发现有个人极端暴利重点人员，请进行关注。";
                        v.put("yjMsg",yjMsg);
                        resue.add(v);
                    }
                }
            }
        }

        return resue;
    }
}
